<template>
	<view class="bg-white">
		<cu-custom :bgColor="globalData.bgColor" :isBack="true">
			<block slot="content"><text class="text-darkgrey">明细详情</text></block>
		</cu-custom>
		<view class="search">
			<scroll-view scroll-x class="bg-white nav solid-bottom text-center">
				<view class="cu-item " :class="index==TabCur?'text-blue cur':''" v-for="(item,index) in tabs" :key="index"
				@tap="tabSelect" :data-id="index">{{item}}</view>
			</scroll-view>
		</view>
		<mescroll-body class="bg-gray" style="margin-top:90rpx;"  ref="mescrollRef"  @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption" >
			<view class="cu-list coupon-list" v-if="TabCur==1" >
			    <view class="cu-item radius bg-white solid-top padding"  v-for="data in dataList" :key="data.id">
					<view class="flex justify-between">
						<view class="padding-bottom-sm">
							<text class="text-darkgrey margin-right-xs cuIcon-titles">{{data.shopId}}</text>
						</view>
						<view v-if="data.status==0" class="text-xs cu-tag light round bg-blue">未使用</view>
						<view v-else-if="data.status==1" class="text-xs cu-tag light round bg-red">已使用</view>
						<view v-else-if="data.status==2" class="text-xs cu-tag light round bg-orange">已过期</view>
					</view>
					<view class="cu-list menu-avatar flex justify-between">
					    <view class="cu-avatar lg" :style="{'background-image':'url('+ (data.userInfo ? data.userInfo.headimgUrl : '')+')'}">
							<text v-if="!data.userInfo" class="cuIcon-peoplefill"></text>
						</view>
					    <view class="content flex-sub padding-left text-darkgrey margin-top-xs">
							<view class="text-darkgrey text-df">用户编号：{{data.userInfo ? data.userInfo.userCode:''}}</view>
							<view class="text-purple-grey text-sm">用户昵称：{{data.userInfo ? data.userInfo.nickName : ''}}</view>
						</view>
					</view>
					<view class="text-purple-grey text-sm margin-top-xs">电子券名称：{{data.name}}</view>
					<view class="text-purple-grey text-sm">电子券类型：{{data.type==1?'代金券': data.type == '2' ? '折扣券' : ''}}</view>
					<view class="text-purple-grey text-sm">订单满{{data.premiseAmount}}元可使用</view>
					<view class="text-purple-grey text-sm" v-if="data.validBeginTime">有效期：{{data.validBeginTime}}至{{data.validEndTime}}</view>
					<view class="text-purple-grey text-sm" v-if="data.usedTime">使用时间：{{data.usedTime}}</view>
					<view class="text-purple-grey text-sm ">领券时间：{{data.createTime}}</view>
			    </view>
			</view>
			<view class="cu-list " v-if="TabCur==0" >
				<view class="cu-item radius bg-white solid-bottom" v-for="data in dataList" :key="data.id">
					<view class="flex justify-between">
						<view class="padding-top padding-left-sm padding-bottom-sm">
							<text class="text-darkgrey text-sm cuIcon-titles">订单号:{{data.orderNo}}</text>
						</view>
					</view>
					<view class="cu-list menu-avatar flex justify-between padding-left align-center" v-for="item in data.listOrderItem" :key="item.id">
						<view class="cu-avatar img-box bg-white" :style="{'background-image':item.picUrl?'url('+item.picUrl+')':''}"></view>
						<view class="content flex-sub padding-left padding-right">
							<view class="text-darkgrey text-to-long">
								<text v-show="data.orderType != '0'" class="cu-tag text-sm light bg-red margin-right-xs radius">
								{{data.orderType == '1' ? '砍价' : data.orderType == '2' ? '拼团' : data.orderType == '3' ? '秒杀' : ''}}</text>
								{{item.spuName}}</view>
							<view class="text-purple-grey flex justify-between margin-top-xs text-sm">
								<text>规格：{{item.specInfo?item.specInfo:'单规格'}}</text>
								<text>×{{item.quantity}}</text>
							</view>
							<view class="margin-top-xs  justify-between">
								<view class="cu-tab line-orange sm margin-top-xs text-sm">{{item.statusDesc}}</view>
								<view class="text-darkgrey text-sm">支付金额：<text class="text-red text-xl  text-price">{{item.paymentPrice}}{{item.paymentCouponPrice ? ' + 优惠券￥'+item.paymentCouponPrice : ''}}{{item.paymentPoints ? ' + 积分'+item.paymentPoints : ''}}</text>
									
								</view>
							</view>
						</view>
					</view>
					<view class="padding-left padding-right text-sm margin-top" v-if="data.orderLogistics">
						<view class="text-purple-grey"><text class="text-purple-grey cuIcon-deliver margin-right-xs"></text>{{data.deliveryWay==1?'普通快递':'上面自提'}}</view>
						<view v-if="data.deliveryWay==1" class="margin-top-xs">
							<!-- <view class="text-lg text-black ">收货人信息</view> -->
							<view class="text-purple-grey margin-top-xs"><text class="text-purple-grey cuIcon-people margin-right-xs"></text>{{data.orderLogistics.userName +' '}}{{data.orderLogistics.telNum}}</view>
							<view class="margin-top-xs text-purple-grey"><text class="text-purple-grey cuIcon-location margin-right-xs"></text>{{data.orderLogistics.address}}</view>
							<view class="margin-top-xs text-purple-grey"><text class="text-purple-grey cuIcon-time margin-right-xs"></text>{{data.createTime}}</view>
						</view>
					</view>
					<view class="padding-left padding-right text-sm margin-top-xs padding-bottom-xs">
						<view class="text-df text-purple-grey margin-bottom-xs text-sm" v-if="data.orderLogistics&&data.orderLogistics.message"><text
							 class="text-sm">签收信息：</text><text class="text-sm">{{data.orderLogistics.message}}</text></view>
						<view class="text-df text-black flex  justify-between">
							<view class="text-darkgrey">订单总金额：<text class="text-price text-xl text-bold text-red margin-right-xs">{{data.paymentPrice}}</text><text
								 class="text-purple-grey text-sm">(含运费)</text></view>
							<!-- <view class="text-sm text-gray padding-top-xs">{{data.createTime}}</view> -->
						</view>
						<view class="flex margin-top-xs">
							<view class="text-xs margin-right-xs light round pay" v-show="data.appraisesStatus" :class="data.appraisesStatus!=0?'bg-blue':'bg-orange'">{{data.appraisesStatus == '0' ? '未评价' :
							        data.appraisesStatus == '1' ? '已评价' : data.appraisesStatus == '2' ? '已追评' :''}}</view>
							<view class="text-xs margin-right-xs light round pay" :class="data.isPay==1?'bg-cyan':'bg-orange'">{{data.isPay==1?'已支付':'未支付'}}</view>
							<view class="text-xs margin-right-xs light round pay" :class="data.status==2||data.status==3||data.status==4?'bg-blue':'bg-orange'">{{data.statusDesc}}</view>
						</view>
					</view>
					<view class="padding-left padding-right text-sm margin-top-xs padding-bottom-sm flex justify-end">
						<navigator :url="'/pages/mall/order/detail?id='+data.id" class="cu-btn round  bg-blue button-bg shadow-blur">详情查询</navigator>
					</view>
				</view>
			</view>
		</mescroll-body>

	</view>
</template>

<script>
	// 引入mescroll-mixins.js
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	const app = getApp();
	
	  import {getPage as getCouponUser} from '@/api/mall/couponuser'
	  import {getPage as getOrderPage} from '@/api/mall/orderinfo'
	  
	  
	  	import service from "@/store/service";

	export default {
		mixins: [MescrollMixin], // 使用mixin
		components: {},
		onLoad(e) {
			if (e ) {
				this.shopId = e.shopId
				this.userId = e.userId
			}
		},
		onShow(){
			if(this.mescroll){
				this.mescroll.resetUpScroll(); //刷新
			}
		},
		data() {
			return {
				userInfo: {},
				userId: '',
				shopId: '',
				globalData: app.globalData,
				CustomBar: this.CustomBar,
				TabCur: 0,
				scrollLeft: 0,
				tabs: ['消费记录', '领券记录'],
				inputKey: '',
				mescroll: null, // mescroll实例对象 (此行可删,mixins已默认)
				downOption: { // 下拉刷新的配置(可选, 绝大部分情况无需配置)

				},
				// 上拉加载的配置(可选, 绝大部分情况无需配置)
				upOption: {
					page: {
						size: 10 // 每页数据的数量,默认10
					},
					noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
					empty: {
						tip: '暂无相关数据'
					}
				},
				// 列表数据
				dataList: [],
			}
		},
		methods: {
			
			tabSelect(e) {
				this.TabCur = e.currentTarget.dataset.id;
				this.scrollLeft = (e.currentTarget.dataset.id - 1) * 60
				this.mescroll.resetUpScroll();
			},
			search(val) {
				this.mescroll.resetUpScroll();
			},
			/*mescroll组件初始化的回调,可获取到mescroll对象 (此处可删,mixins已默认)*/
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},
			/*下拉刷新的回调, 有三种处理方式:*/
			downCallback() {
				this.mescroll.resetUpScroll(); // 重置列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
				this.mescroll.endSuccess()
			},
			/*上拉加载的回调*/
			upCallback(page) {
				let pageNum = page.num; // 页码, 默认从1开始
				let pageSize = page.size; // 页长, 默认每页10条
							
				let querySearch = '?current=' + pageNum 
				+ '&size=' + pageSize 
				+ '&userId=' + this.userId 
				+ '&shopId=' + this.shopId 
				+ '&descs=create_time';
				
				if (this.TabCur == 0) {//消费记录
					getOrderPage(querySearch).then(response => {
						if (response.data) {
							// 接口返回的当前页数据列表 (数组)
							let curPageData = response.data.records;
							// 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
							let curPageLen = curPageData.length;
							// 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
							let totalSize = response.data.total;
							//设置列表数据
							if (page.num == 1) this.dataList = []; //如果是第一页需手动置空列表
							this.dataList = this.dataList.concat(curPageData); //追加新数据
							// 请求成功,隐藏加载状态
							this.mescroll.endBySize(curPageLen, totalSize);
							setTimeout(() => {
								this.mescroll.endSuccess(curPageLen)
							}, 20)
						}
					});
				}else {//电子券记录
					getCouponUser(querySearch).then(response => {
						if (response.data) {
							// 接口返回的当前页数据列表 (数组)
							let curPageData = response.data.records;
							// 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
							let curPageLen = curPageData.length;
							// 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
							let totalSize = response.data.total;
							//设置列表数据
							if (page.num == 1) this.dataList = []; //如果是第一页需手动置空列表
							this.dataList = this.dataList.concat(curPageData); //追加新数据
							// 请求成功,隐藏加载状态
							this.mescroll.endBySize(curPageLen, totalSize);
							setTimeout(() => {
								this.mescroll.endSuccess(curPageLen)
							}, 20)
						}
					});
				}
				
			}
		}
	}
</script>

<style>
	.search {
		width: 100%;
		padding-bottom: 20rpx;
		position: fixed;
		z-index: 9999;
	}

	.search-content {
		background-color: #f5f5f5;
		line-height: 64upx;
		height: 64upx;
		font-size: 24upx;
		color: #333333;
		flex: 1;
		display: flex;
		align-items: center;
		margin: 0 30upx;
	}

	.search-content input {
		flex: 1;
		padding-right: 30upx;
		height: 64upx;
		line-height: 64upx;
		font-size: 26upx;
		background-color: transparent;
	}

	.search-button {
		padding: 10rpx 30rpx 10rpx 30rpx;
	}

	

	

	.img-box {
		width: 200rpx !important;
		height: 200rpx !important;
	}

	.pay {
		padding: 10rpx 20rpx 10rpx 20rpx;
	}

	.button-bg {
		padding: 20rpx 40rpx 20rpx 40rpx;
	}

	.text-to-long {
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		overflow: hidden;
	}
</style>
